<template>
	<view></view>
</template>
<script>
	import request from '@/api/request.js';
	import {ztColor} from '@/api/color.js';
	export default {
		onLoad() {
		},
		onShow() {
			this.getInfoColor();
		},
		onHide() {
			console.log('隐藏')
		},
		onUnload() {
			console.log('卸载')
		},
		watch: {
			'$store.state.present': {
				handler(newVal) {
					// 设置导航栏颜色
					uni.setNavigationBarColor({
						frontColor: '#ffffff',
						backgroundColor: this.$store.state.presentColor
					});
				},
				deep: true,
				immediate: true
			}
		},
		methods: {
			// 更改tarbar图片和导航栏颜色
			changeColor(zt){
				if(zt === '蓝色'){
					uni.setTabBarStyle({
					  selectedColor: this.$store.state.presentColor,
					});
					uni.setTabBarItem({
					  index: 0,
					  selectedIconPath: '/static/home_icon/home_icon01aBlue.png',
					  iconPath: "/static/home_icon/home_icon01.png",
					  text: "首页"
					});
					uni.setTabBarItem({
					  index: 1,
					  selectedIconPath: '/static/home_icon/home_icon04aBlue.png',
					  iconPath: "/static/home_icon/home_icon04.png",
					  text: "新闻"
					});
					uni.setTabBarItem({
					  index: 2,
					  selectedIconPath: '/static/home_icon/home_icon03aBlue.png',
					  iconPath: "/static/home_icon/home_icon03.png",
					  text: "交易"
					});
					uni.setTabBarItem({
					  index: 3,
					  selectedIconPath: '/static/home_icon/home_icon02aBlue.png',
					  iconPath: "/static/home_icon/home_icon02.png",
					  text: "资产"
					});
					uni.setTabBarItem({
					  index: 4,
					  selectedIconPath: '/static/home_icon/home_icon05aBlue.png',
					  iconPath: "/static/home_icon/home_icon05.png",
					  text: "我的"
					});
					this.$store.commit("skinPeeler",ztColor[1].value);
				}
			},
			// 获取主题颜色
			async getInfoColor(){
				let data = await request.get('/api/common/getCurrentThemeConfig');
				if(data.code === 1){
					// red / blue
					let str = data.data === 'red' ? '红色' : '蓝色';
					console.log(str)
					let color = '';
					if(str === '红色'){
						color = '#f11b25'
					}else if (str === '蓝色') {
						color = '#1b8fff'
					}
					this.$store.commit("changePresent",{str,color});
					let zt = this.$store.state.present;
					this.changeColor(zt);
				}
			}
		}
	}
</script>
<style>
	/*每个页面公共css */
	/* @import url("css/tix.css"); */
	@import url("css/aui.css");
	.page {
		width: 100%;
		height: 100%;
		background-color: rgb(245, 245, 245) !important;
		font-family: PingFangSC-Light, 'helvetica neue', 'hiragino sans gb', tahoma, 'microsoft yahei ui', 'microsoft yahei', simsun, sans-serif;
		color: #282828;
		margin: 0px;
		padding: 0px;
	}
	.container {
		position: absolute;
		background: #f2f2f2;
		color: #282828;
		height: 100%;
		width: 100%;
		margin: 0px;
		padding: 0px;
	}
</style>